home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / c / amiexpress / source / doors / dand / dand.c next >
Encoding:
C/C++ Source or Header  |  1992-12-26  |  9.1 KB  |  354 lines

  1. #include "work:romconf/includes.h"
  2. #include "work:romconf/doorheader.h"
  3. #include "struct.h"
  4. #define c1 ansi?"":""
  5. #define c2 ansi?"":""
  6. #define c3 ansi?"":""
  7. #define c4 ansi?"":""
  8. #define c5 ansi?"":""
  9. #define c6 ansi?"":""
  10. #define c7 ansi?"":""
  11. #define SM sendmessage
  12. #define PM prompt
  13. #define HK hotkey
  14. #define GU getuserstring
  15. #define BRIEF 1
  16.  
  17. void DisplayMap(int x,int y);
  18. void GetCommands();
  19. void LoadMap();
  20. void ShowCharacters(int Num,int Option);
  21. char *GetTheDate();
  22. char Map[9][12];
  23. int x,y;
  24. int UserNum=-1;
  25. main(int argc,char *argv[])
  26. {
  27.  
  28.    Register(argv[1][0]-'0');
  29.    x=y=0;
  30.    if(!GetLogon()) { ShutDown(); end(); }
  31.    LoadMap();
  32.    GetCommands();
  33. }
  34.  
  35. int GetLogon()
  36. {
  37.   FILE *fi;
  38.   char CMD[200];
  39.   getuserstring(CMD,DT_NAME);
  40.   int UserNum =0;
  41.   int Slot = -1; 
  42.   strupr(CMD);
  43.   InitStructures();
  44.   fi=fopen("DOORS:DAND/User.dta","r+b");
  45.   if(fi==NULL)
  46.   {
  47.     if(GetNewAccount())
  48.      return(1); else return(0);
  49.   }
  50.  
  51.   while(fread((APTR)&Player,sizeof(struct User),1,fi)!=NULL)
  52.   {
  53.   
  54.     if(!strcmp(CMD,Player.UserName))
  55.     {
  56.        fclose(fi);
  57.        return(1);
  58.     }
  59.     if(Player.Slot==-1) Slot=UserNum;
  60.     UserNum +=1;
  61.   }
  62.   fclose(fi);
  63.   InitStructures();
  64.   Player.Slot= (Slot==-1?UserNum:Slot);
  65.   if(GetNewAccount()) return(1); else return(0);
  66. }
  67.  
  68. int GetNewAccount()
  69. {
  70.   char CMD[200];
  71.   FILE *fi;
  72.   sprintf(CMD,"%sYou must be new to this Realm. Would you like to participate in",c6);
  73.   SM(CMD,1);
  74.   sprintf(CMD,"%sByteMaster's%s Dungeons ",c1,c6);
  75.   SM(CMD,0); 
  76.   if(YesNo())
  77.   {
  78.      fi=fopen("DOORS:DAND/User.dta","r+b");
  79.      if(fi==NULL)
  80.      {
  81.        fi=fopen("DOORS:DAND/User.dta","wb");
  82.      }
  83.      if(fseek(fi,(LONG)sizeof(struct User)*(LONG)Player.Slot,SEEK_SET))
  84.      {
  85.        fclose(fi); fi=fopen("DOORS:DAND/User.dta","ab");
  86.      }
  87.      fwrite((APTR)&Player,sizeof(struct User),1,fi);
  88.      fclose(fi);
  89.      GetUserData();
  90.      return(1);
  91.   }
  92.   return(0);
  93. }
  94. void GetUserData()
  95. {
  96.   char CMD[200];
  97.   int i=0;
  98.   while(1)
  99.   {
  100.     sprintf(CMD,"%sPlease enter an Alias >:",c4);
  101.     PM(CMD,CMD,30);
  102.     SM("Are you sure ",0); if(YesNo()) break;
  103.   }
  104.   strcpy(Player.Handle,CMD);
  105.   SM("Now you must create 4 characters.",1);
  106.   while(i<4)
  107.   {
  108.     sprintf(CMD,"%sCreating Character %s[%s%d%s]%s",c2,c6,c3,i+1,c6,"");
  109.     SM(CMD,1);
  110.     while(1)
  111.     {
  112.       sprintf(CMD,"%sPlease enter character name >:%s",c2,c4);
  113.       PM(CMD,CMD,20);
  114.       SM("Are you sure ",0); if(YesNo()) break;
  115.     }
  116.     strcpy(Player.Party[i].Leader);
  117.     while(1)
  118.     {
  119.     
  120.       sprintf(CMD,"%sPlease choose from the following classes:%s (%sMaybe more than 1%s)",c2,c3,c1,c3);
  121.       SM(CMD,1);
  122.       sprintf(CMD,"%s[%sF%s]ighter, [%sC%s]leric, [%sT%s]hief, [%sM%s]agicUser",c6,c3,c6,c3,c6,c3,c6,c3,c6);
  123.       SM(CMD,1);
  124.       HK(">:",CMD);
  125.       strupr(CMD);
  126.       if(CMD[0]!='F' && CMD[0]!='C' && CMD[0]!='T' && CMD[0]!='M')
  127.       { 
  128.         if(Player.Party[i].Class[0]!=' ' || Player.Party[i].Class[1]!=' ' ||
  129.            Player.Party[i].Class[2]!=' ' || Player.Party[i].Class[3]!=' ') break;
  130.       }
  131.       else switch(CMD[0])
  132.       {
  133.         case 'F': Player.Party[i].Class[0]=(Player.Party[i].Class[0]=='F'?' ':'F'); break;
  134.         case 'C': Player.Party[i].Class[1]=(Player.Party[i].Class[1]=='C'?' ':'C'); break;
  135.         case 'T': Player.Party[i].Class[2]=(Player.Party[i].Class[2]=='T'?' ':'T'); break;
  136.         case 'M': Player.Party[i].Class[3]=(Player.Party[i].Class[3]=='M'?' ':'M'); break;
  137.       }
  138.       sprintf(CMD,"Character %s is currently a",Player.Party[i].Leader);
  139.       SM(CMD,1);
  140.       if(Player.Party[i].Class[0]!=' ') SM("FIGHTER ",0);
  141.       if(Player.Party[i].Class[1]!=' ') SM("CLERIC  ",0);
  142.       if(Player.Party[i].Class[2]!=' ') SM("THIEF   ",0);
  143.       if(Player.Party[i].Class[3]!=' ') SM("MAGIC USER ",0);
  144.       SM("",1);
  145.     } 
  146.    while(1)
  147.     {
  148.     
  149.       sprintf(CMD,"%sPlease choose from the following races:",c2);
  150.       SM(CMD,1);
  151.       sprintf(CMD,"%s[%sH%s]uman, [%sE%s]lf, [%sD%s]warf",c6,c3,c6,c3,c6,c3,c6);
  152.       SM(CMD,1);
  153.       HK(">:",CMD);
  154.       strupr(CMD);
  155.       if(CMD[0]!='H' && CMD[0]!='E' && CMD[0]!='D')
  156.       { 
  157.         if(Player.Party[i].Race[0]!='\0') break;
  158.       }
  159.       else switch(CMD[0])
  160.       {
  161.         case 'H': strcpy(Player.Party[i].Race,"Human"); break;
  162.         case 'E': strcpy(Player.Party[i].Race,"Elf"); break;
  163.         case 'D': strcpy(Player.Party[i].Race,"Dwarf"); break;
  164.       }
  165.       sprintf(CMD,"Character %s is currently a %s",Player.Party[i].Leader,Player.Party[i].Race);
  166.       SM(CMD,1);
  167.     } 
  168.             
  169. }
  170. int YesNo()
  171. {
  172.   char CMD[20];
  173.   sprintf(CMD,"%s[%sY%s/%sn%s] >:",c6,c2,c6,c1,c6);
  174.   HK(CMD,CMD);
  175.   strupr(CMD);
  176.   if(CMD[0]=='N') { SM("No.",1);return(0);}
  177.   SM("Yes.",1); return(0);
  178. }
  179.     
  180. void LoadMap()
  181. {
  182.    FILE *fi;
  183.    int i=0;
  184.    fi=fopen("DOORS:DAND/MAP.DAT","r");
  185.    if(fi==NULL)
  186.    {
  187.      SM("Can't locate Map.",1);
  188.      ShutDown(); end();
  189.    }
  190.    while(fgets((char *)Map[i],10,fi)!=NULL) i++;
  191.    fclose(fi);
  192. }
  193.  
  194. InitStructures()
  195. {
  196.   int i=0;
  197.   int j=0;
  198.   while(i<8)
  199.   {
  200.      strcpy(Player.Party[i].Leader,"");
  201.      strcpy(Player.Party[i].Race,"");
  202.      Player.Party[i].HenchMen=0;
  203.      Player.Party[i].HenchLevel=0;
  204.      Player.Party[i].Class[0]=' ';
  205.      Player.Party[i].Class[1]=' ';
  206.      Player.Party[i].Class[2]=' ';
  207.      Player.Party[i].Class[3]=' ';
  208.      Player.Party[i].Class[4]=' ';
  209.      Player.Party[i].Experience[0]=0L;
  210.      Player.Party[i].Experience[1]=0L;
  211.      Player.Party[i].Experience[2]=0L;
  212.      Player.Party[i].Experience[3]=0L;
  213.      Player.Party[i].Experience[4]=0L;
  214.      Player.Party[i].Level[0]=0;
  215.      Player.Party[i].Level[1]=0;
  216.      Player.Party[i].Level[2]=0;
  217.      Player.Party[i].Level[3]=0;
  218.      Player.Party[i].Level[4]=0;
  219.      j=0;
  220.      while(j<60) 
  221.      {
  222.         Player.Party[i].Equipment[j]=' '; j++;
  223.      }
  224.      Player.Party[i].Credits=0L;
  225.      Player.Party[i].ArmorClass=9;
  226.      Player.Party[i].MaxPoints=0;
  227.      j=0; while(j<5) 
  228.      {
  229.        Player.Party[i].Attributes[j]=0;
  230.        Player.Party[i].MaxAttributes[j]=0;
  231.        j++;
  232.      }
  233.     i++;
  234.   }
  235.   strcpy(Player.UserName,"");
  236.   strcpy(Player.Handle,"");
  237.   strcpy(Player.LastOn,"");
  238.   Player.SlotNum=0;
  239. }
  240.      
  241. void GetCommands()
  242. {
  243.    char CMD[200];
  244.    int x1,y1;
  245.    int error=0;
  246.    while(1)
  247.    {
  248.       ShowCharacters(-1,BRIEF);
  249.       DisplayMap(x,y);
  250.       do
  251.       {
  252.          HK("Please enter command [N,S,E,W,Q] >:",CMD);
  253.          strupr(CMD);
  254.       }while(CMD[0]!='N' && CMD[0]!='S' && CMD[0]!='E' && CMD[0]!='W' &&
  255.              CMD[0]!='Q');
  256.       switch(CMD[0])
  257.       {
  258.          case 'N': SM("North.",1); x1=x;y1=y;
  259.                    y1 -=1; 
  260.                    if(y1<0) { SM("Can't go that direction.",1); break; }
  261.                    if(Map[y1][x1]=='0') 
  262.                             { SM("Ouch!",1); break; }
  263.                    x=x1;y=y1;
  264.                    break;
  265.          case 'S': SM("South.",1); x1=x;y1=y;
  266.                    y1 +=1; 
  267.                    if(y1>7) { SM("Can't go that direction.",1); break; }
  268.                    if(Map[y1][x1]=='0') 
  269.                             { SM("Ouch!",1); break; }
  270.                    x=x1;y=y1;
  271.                    break;
  272.          case 'E': SM("East.",1); x1=x;y1=y;
  273.                    x1 +=1; 
  274.                    if(x1>7) { SM("Can't go that direction.",1); break; }
  275.                    if(Map[y1][x1]=='0') 
  276.                             { SM("Ouch!",1); break; }
  277.                    x=x1;y=y1;
  278.                    break;
  279.          case 'W': SM("West.",1); x1=x;y1=y;
  280.                    x1 -=1; 
  281.                    if(x1<0) { SM("Can't go that direction.",1); break; }
  282.                    if(Map[y1][x1]=='0') 
  283.                             { SM("Ouch!",1); break; }
  284.                    x=x1;y=y1;
  285.                    break;
  286.          default: 
  287.             SM("Quit.",1); ShutDown(); end();
  288.        }
  289.     }
  290. }
  291. ShowCharacters(int Num,int Option)
  292. {
  293.   FILE *fi;
  294.   
  295. void DisplayMap(int x,int y)
  296. {
  297.    char FileName[200];
  298.    sprintf(FileName,"DOORS:DAND/ROOM%c",Map[y][x]);
  299.    showgfile(FileName);
  300. }
  301. char *GetTheDate()
  302. {
  303.   struct tm *tp;
  304.   long t;
  305.   int M,D,Y;
  306.   char Date[9];
  307.   char Day[4],Month[5],Year[3];
  308.   char TheTime[27];
  309.   time(&t);
  310.   tp=localtime(&t);
  311.   sprintf(TheTime,"%s",asctime(tp));
  312.   sprintf(Day,"%.2s",&TheTime[8]);
  313.   sprintf(Month,"%.3s",&TheTime[4]);
  314.   sprintf(Year,"%.2s",&TheTime[22]);
  315.    D=atoi(Day);
  316.    Y=atoi(Year);
  317.  
  318.   if(!strncmp(Month,"Jan",3)) M=1;
  319.   if(!strncmp(Month,"Feb",3)) M=2;
  320.   if(!strncmp(Month,"Mar",3)) M=3;
  321.   if(!strncmp(Month,"Apr",3)) M=4;
  322.   if(!strncmp(Month,"May",3)) M=5;
  323.   if(!strncmp(Month,"Jun",3)) M=6;
  324.   if(!strncmp(Month,"Jul",3)) M=7;
  325.   if(!strncmp(Month,"Aug",3)) M=8;
  326.   if(!strncmp(Month,"Sep",3)) M=9;
  327.   if(!strncmp(Month,"Oct",3)) M=10;
  328.   if(!strncmp(Month,"Nov",3)) M=11;
  329.   if(!strncmp(Month,"Dec",3)) M=12; 
  330.   sprintf(Date,"%02d-%02d-%02d",M,D,Y);
  331.   return(Date);
  332. }
  333. char *GetDiff(char *Date1,char *Date2)
  334. {
  335.   char D1[9],D2[9];
  336.   int Month1,Day1,Year1;
  337.   int Month2,Day2,Year2;
  338.   int Total;
  339.   strcpy(D1,Date1); strcpy(D2,Date2);
  340.   if(D1[0]=='\0') return(5);
  341.   Month2=atoi(D2);
  342.   Day2=atoi(&D2[2]);
  343.   Year2=atoi(&D2[5]);
  344.   Month1=atoi(D1);
  345.   Day1=atoi(&D1[2]);
  346.   Year1=atoi(&D1[5]);
  347.  
  348.   if(Day2<Day1) Total=31-Day1+Day2;
  349.   else Total=Day2-Day1;
  350.   if(Month2<Month1) Total +=(12-Month1+Month2)*30;
  351.   else if(Month2>Month1) Total +=(Month2-Month1)*30;
  352.   return(Total);
  353. }
  354.